home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DDJMAG
/
DDJ9110.ZIP
/
STRING.ZIP
/
STRITRUN.CPP
< prev
Wrap
C/C++ Source or Header
|
1991-07-30
|
506b
|
29 lines
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <string.hpp>
String &String::truncate(int n)
{
if (n >= length())
return *this;
srep *p;
if (!n)
p = 0;
else {
p = new(n) srep(n);
if (!p) {
errno = ENOMEM;
return *this;
}
memmove(p->body,body(),n);
}
if (rp) {
if (--rp->refs < 1)
delete rp;
}
rp = p;
rp->refs++;
return *this;
}